﻿#include "DesignModel.h"

DesignModel::DesignModel(QObject *parent)
    : QObject(parent)
{
}

DesignModel::DesignModel(const bool &enable,
                         const int &keyMode,
                         const QString &startKey,
                         const QString &stopKey,
                         const QString &sequenceKey,
                         const QString &interval, QObject *parent)
    : QObject(parent),
      m_enable(enable),
      m_keyMode(keyMode),
      m_startKey(startKey),
      m_stopKey(stopKey),
      m_sequenceKey(sequenceKey),
      m_interval(interval)
{
}

bool DesignModel::enable() const
{
    return m_enable;
}

void DesignModel::setEnable(const bool &enable)
{
    m_enable = enable;
    emit enableChanged();
}

bool DesignModel::running() const
{
    return m_running;
}

void DesignModel::setRunning(const bool &running)
{
    m_running = running;
}

QString DesignModel::startKey() const
{
    return m_startKey;
}

void DesignModel::setStartKey(const QString &startKey)
{
    m_startKey = startKey;
    emit startKeyChanged();
}

QString DesignModel::stopKey() const
{
    return m_stopKey;
}

void DesignModel::setStopKey(const QString &stopKey)
{
    m_stopKey = stopKey;
    emit stopKeyChanged();
}

QString DesignModel::sequenceKey() const
{
    return m_sequenceKey;
}

void DesignModel::setSequenceKey(const QString &sequenceKey)
{
    m_sequenceKey = sequenceKey;
    emit sequenceKeyChanged();
}

QString DesignModel::interval() const
{
    return m_interval;
}

void DesignModel::setInterval(const QString &interval)
{
    m_interval = interval;
    emit intervalChanged();
}

int DesignModel::keyMode() const
{
    return m_keyMode;
}

void DesignModel::read(const QJsonObject &json)
{

    if (json.contains("enable") && json["enable"].isBool())
        m_enable = json["enable"].toBool();

    if (json.contains("keyMode") && json["keyMode"].isDouble())
        m_keyMode = json["keyMode"].toInt();

    if (json.contains("startKey") && json["startKey"].isString())
        m_startKey = json["startKey"].toString();

    if (json.contains("stopKey") && json["stopKey"].isString())
        m_stopKey = json["stopKey"].toString();

    if (json.contains("sequenceKey") && json["sequenceKey"].isString())
        m_sequenceKey = json["sequenceKey"].toString();

    if (json.contains("interval") && json["interval"].isString())
        m_interval = json["interval"].toString();
}

void DesignModel::write(QJsonObject &json) const
{
    json["enable"] = m_enable;
    json["keyMode"] = m_keyMode;
    json["startKey"] = m_startKey;
    json["stopKey"] = m_stopKey;
    json["sequenceKey"] = m_sequenceKey;
    json["interval"] = m_interval;
}
